package com.icexxx.icemock.mock;

import cn.hutool.core.util.RandomUtil;

public class IpMock implements IceMock {

	@Override
	public String mock(Integer minVal, Integer maxVal, Integer minWidth, Integer maxWidth, String enums, String key) {
		int probability = RandomUtil.randomInt(3);
		if (probability == 0) {
			return mockAddreA();
		} else if (probability == 1) {
			return mockAddreB();
		} else if (probability == 2) {
			return mockAddreC();
		}
		return "127.0.0.1";
	}

	private String mockAddreA() {
		int randomInt1 = RandomUtil.randomInt(2, 255);
		int randomInt2 = RandomUtil.randomInt(2, 255);
		int randomInt3 = RandomUtil.randomInt(2, 255);
		StringBuilder sb = new StringBuilder();
		sb.append("10.");
		sb.append(randomInt1);
		sb.append(".");
		sb.append(randomInt2);
		sb.append(".");
		sb.append(randomInt3);
		return sb.toString();
	}

	private String mockAddreB() {
		int randomInt1 = RandomUtil.randomInt(16, 32);
		int randomInt2 = RandomUtil.randomInt(2, 255);
		int randomInt3 = RandomUtil.randomInt(2, 255);
		StringBuilder sb = new StringBuilder();
		sb.append("172.");
		sb.append(randomInt1);
		sb.append(".");
		sb.append(randomInt2);
		sb.append(".");
		sb.append(randomInt3);
		return sb.toString();
	}

	private String mockAddreC() {
		int randomInt1 = RandomUtil.randomInt(16, 32);
		int randomInt2 = RandomUtil.randomInt(2, 255);
		StringBuilder sb = new StringBuilder();
		sb.append("192.168.");
		sb.append(randomInt1);
		sb.append(".");
		sb.append(randomInt2);
		return sb.toString();
	}
}
